package org.je.io;

import org.je.cons.JCons;

/**
 * @author fanyifeng
 */
public class IOUtil
{
	/**
	 * @param s
	 * @return bytes
	 */
	public static byte[] utf8(String s) {
		if (s == null)
			return null;
		if (s.length() == 0)
			return new byte[0];
		try {
			return s.getBytes(JCons.enc().utf8);
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

	/**
	 * @param b
	 * @return str
	 */
	public static String utf8(byte[] b) {
		if (b == null)
			return null;
		if (b.length == 0)
			return "";
		try {
			return new String(b, JCons.enc().utf8);
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
}
